package com.dragon.codefx.controller;

import javafx.animation.*;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.util.Duration;
import org.springframework.stereotype.Component;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * 首页控制类
 *
 * @author lsc
 * @since 2025/9/26 10:43
 **/
@Component
public class IndexController implements Initializable {


    @FXML
    private Circle shape1, shape2;
    @FXML
    private Button startButton;
    @FXML
    private Label footerLabel;
    @FXML
    private Pane backgroundPane;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        // 设置页脚年份
        footerLabel.setText("代码生成器 © " + java.time.Year.now().getValue());
        setupButtonAnimations();
    }


    private void setupButtonAnimations() {
        // 鼠标悬停动画
        startButton.setOnMouseEntered(e -> {
            startButton.setTranslateY(-2);
            startButton.setEffect(new javafx.scene.effect.DropShadow(12, Color.rgb(33, 150, 243, 0.6)));
        });

        startButton.setOnMouseExited(e -> {
            startButton.setTranslateY(0);
            startButton.setEffect(new javafx.scene.effect.DropShadow(8, Color.rgb(33, 150, 243, 0.4)));
        });

        // 点击事件
        startButton.setOnAction(e -> {
            ScaleTransition scaleTransition = new ScaleTransition(Duration.millis(150), startButton);
            scaleTransition.setToX(0.95);
            scaleTransition.setToY(0.95);
            scaleTransition.setAutoReverse(true);
            scaleTransition.setCycleCount(2);
            scaleTransition.play();

            // 导航到下一个页面
            scaleTransition.setOnFinished(event -> {
                // 这里添加页面跳转逻辑
                System.out.println("跳转到JDBC配置页面");
            });
        });
    }

}
